package comet;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class EtudiantTestBean implements EtudiantTestBeanRemote {

	@PersistenceContext(name = "Etudiant")
	private EntityManager em; //L'Entity Manager

	public void addEtudiant(Etudiant var) {
		em.persist(var);
	}

	public Etudiant rechercherEtudiant(int var) {
		return em.find(Etudiant.class, var);
	}

	public void deleteEtudiant(int var) {
		Etudiant resReq = rechercherEtudiant(var);
		if (resReq != null) {
			em.remove(resReq);
		}
	}

	public List<Etudiant> listerTousLesEtudiant() {
		return em.createQuery("SELECT * FROM TableEtudiant  ").getResultList();
	}

	public Etudiant updateEtudiant(Etudiant var1, Etudiant var2) {
		Etudiant var = em.find(Etudiant.class, var1.getNinscription());
		if (var != null) {
			var.setNinscription(var2.getNinscription());

			var.setNom(var2.getNom());

			var.setPrenom(var2.getPrenom());

		}

		return var;
	}

}
